package cn.rs.lvt.entityview;

import cn.rs.lvt.entity.AccessTokenEntity;
import cn.rs.lvt.entity.UserEntity;
import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.EntityViewRoot;
import com.blazebit.persistence.view.EntityViewRoots;
import com.blazebit.persistence.view.Mapping;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * AccessTokenEntity 的视图类, 这种方式不需要实体类里记录关联关系
 */

@Data
@AllArgsConstructor// @EntityView 必须要有全参构造
@EntityView(AccessTokenEntity.class)
@EntityViewRoots({
        @EntityViewRoot(
                name = "userEntity", // 别名
                entity = UserEntity.class,
                condition = "this.uid = userEntity.id" // join 关系
        )
})
public class TokenEntityView {

    @Mapping("id")
    String id;

    @Mapping("uname")
    String uname;

    @Mapping("userEntity.realname")
    String realname;
}
